package com.zq.im.activity;

import android.content.Intent;
import android.widget.Toast;

import com.gyf.immersionbar.ImmersionBar;
import com.zq.im.BaseActivity;
import com.zq.im.R;
import com.zq.im.adapter.FriendRequestedListAdapter;
import com.zq.im.api.FriendsApi;
import com.zq.im.bean.BaseModel;
import com.zq.im.bean.RequestedFriendListBean;
import com.zq.im.retrofit.BaseCallBack;
import com.zq.im.retrofit.RetrofitManager;
import com.zq.im.utils.SharePreferenceUtils;

import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * 好友请求列表
 */
public class FriendRequestListActivity extends BaseActivity {

    @BindView(R.id.friend_requested_list_recyclerview)
    RecyclerView friendRequestedListRecyclerView;

    private List<RequestedFriendListBean> mRequestedFriends;
    private FriendRequestedListAdapter mAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_friends;
    }

    @Override
    protected void initImmersionBar() {
        ImmersionBar.with(this)
                .titleBarMarginTop(R.id.toolbar)
                .barColor(R.color.default_white)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void initView() {
        friendRequestedListRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
        mAdapter = new FriendRequestedListAdapter(this, mRequestedFriends);
        friendRequestedListRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        FriendsApi friendsApi = RetrofitManager.getRetrofit().create(FriendsApi.class);
        Call<BaseModel<List<RequestedFriendListBean>>> requestedFriends = friendsApi.getRequestedFriends(SharePreferenceUtils.getString(
                "userId"));

        requestedFriends.enqueue(new BaseCallBack<List<RequestedFriendListBean>>() {
            @Override
            public void onSuccess(List<RequestedFriendListBean> requestedFriendListBeans) {
                mRequestedFriends = requestedFriendListBeans;
                mAdapter.setRequestedFriends(mRequestedFriends);
                mAdapter.notifyDataSetChanged();

            }

            @Override
            public void onFailure(Throwable t) {

            }
        });
    }

    @OnClick({R.id.search_friend, R.id.add_friend})
    void searchFriend() {
        startActivity(new Intent(this, SearchFriendActivity.class));
    }
}